home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0838 / wftp.h < prev    next >
C/C++ Source or Header  |  1994-10-19  |  8KB  |  188 lines

  1.  
  2. /* *************************************************************** */
  3. /*                                                                 */
  4. /*                                                                 */
  5. /*                                                                 */
  6. /*    WFTP.DLL  (Version 1.0)                                      */
  7. /*                                                                 */
  8. /*                                                                 */
  9. /*                                   By Ph. Jounin (SNCF 71-26-12) */
  10. /*                                        Internet ark@ifh.sncf.fr */
  11. /*                                        Thanks to Santanu Lahiri */
  12. /* *************************************************************** */
  13.  
  14.  
  15. #ifndef WFTP_API
  16.  
  17. #include <winsock.h>
  18.  
  19. #ifdef DEBUG
  20. #  define  FTP_DATABUFFER  256                 /* slown down the transfer */
  21. #else
  22. #  define  FTP_DATABUFFER  1400 /* best value for X25/Ethernet/Token Ring */
  23. #endif
  24.  
  25.  
  26.  
  27. /* ----------------------------------------------------------- */
  28.  
  29. /* ASCII or binary tranfser */
  30. #define   TYPE_A   'A'
  31. #define   TYPE_I   'I'
  32.  
  33.  
  34. /* ----------------------------------------------------------- */
  35. /*              Return codes of FTP functions                  */
  36. /* ----------------------------------------------------------- */
  37. /* success */
  38. #define   FTPERR_OK                    0 // succesful function
  39. #define   FTPERR_ENTERPASSWORD         1 // userid need a password
  40. #define   FTPERR_ACCOUNTNEEDED         2 // user/pass OK but account required
  41. #define   FTPERR_CANCELBYUSER         -1 // Transfer aborted by user (FtpAbort)
  42. /* user's or programmer's Errors  */
  43. #define   FTPERR_SESSIONUSED        1001 // User has already a FTP session
  44. #define   FTPERR_NOTINITIALIZED     1002 // FtpInit has not been call
  45. #define   FTPERR_NOTCONNECTED       1003 // User is not connected to a server
  46. #define   FTPERR_CANTOPENFILE       1004 // can not open specified file
  47. #define   FTPERR_CANTWRITE          1005 // can't write into file (disk full ?)
  48. #define   FTPERR_NOACTIVESESSION    1006 // FtpRelease without FtpInit
  49. #define   FTPERR_STILLCONNECTED     1007 // FtpRelease without any Close
  50. #define   FTPERR_SERVERCANTEXECUTE  1008 // file action not taken 
  51. #define   FTPERR_LOGINREFUSED       1009 // Server rejects usrid/passwd
  52. #define   FTPERR_NOREMOTEFILE       1010 // server can not open file
  53. #define   FTPERR_TRANSFERREFUSED    1011 // Host refused the transfer
  54. #define   FTPERR_WINSOCKNOTUSABLE   1012 // A winsock.DLL ver 1.1 is required
  55. /* TCP errors */
  56. #define   FTPERR_UNKNOWNHOST        2001 // can not resolve host adress
  57. #define   FTPERR_NOREPLY            2002 // host does not send an answer
  58. #define   FTPERR_CANTCONNECT        2003 // Error during connection
  59. #define   FTPERR_CONNECTREJECTED    2004 // host has no FTP server
  60. #define   FTPERR_SENDREFUSED        2005 // can't send data (network down)
  61. #define   FTPERR_DATACONNECTION     2006 // connection on data-port failed
  62. #define   FTPERR_TIMEOUT            2007 // timeout occured
  63. /* FTP errors */
  64. #define   FTPERR_UNEXPECTEDANSWER   3001  // answer was not expected
  65. #define   FTPERR_CANNOTCHANGETYPE   3002  // host rejects the TYPE command
  66. /* Resource errors */
  67. #define   FTPERR_CANTCREATEWINDOW   5002  // Insufficent free resources
  68. #define   FTPERR_INSMEMORY          5003  // Insuffisent Heap memory
  69. #define   FTPERR_CANTCREATESOCKET   5004  // no more socket
  70. #define   FTPERR_CANTBINDSOCKET     5005  // bind is not succesful
  71.  
  72.  
  73. /* ----------------------------------------------------------- */
  74.  
  75. struct S_FtpData
  76. {
  77.    SOCKET   ctrl_socket;    /* control stream      init INVALID_SOCKET */
  78.    SOCKET   data_socket;    /* data stream         init INVALID_SOCKET */
  79.    SOCKET   listen_socket;  /* listen socket       init INVALID_SOCKET */
  80.    char     cType;          /* type (ASCII/binary) init TYPE_A         */
  81.    BOOL     bVerbose;       /* verbose mode        init FALSE          */ 
  82.    char     szInBuf [512];  /* reception Buffer                        */
  83.    char     szOutBuf [512]; /* incoming buffer                         */
  84.    struct sockaddr_in saSockAddr;   
  85.    struct sockaddr_in saAcceptAddr;
  86. }; /* struct S_FtpData */
  87.  
  88.  
  89. struct S_FileTrf 
  90. {
  91.    HFILE    hf;         /* handle of the file which is being transfered */
  92.    unsigned nCount;     /* number of writes/reads made on a file        */
  93.    BOOL     bAborted;   /* data transfer has been canceled              */
  94.    char     szBuf[FTP_DATABUFFER]; /* Data buffer                       */
  95.    BOOL     bNotify;    /* application receives a msg each data packet  */
  96. }; /* struct S_FileTrf */
  97.  
  98. struct S_Msg
  99. {
  100.    HWND          hParentWnd;        // window which the message is to be passed
  101.    UINT          nCompletedMessage; // msg to be sent at the end of the function
  102. };  /* struct S_Msg */
  103.  
  104.  
  105. struct S_Verbose
  106. {
  107.    HWND          hVerboseWnd;  // window which the message is to be passed
  108.    UINT          nVerboseMsg;  // msg to be sent each time a ctrl line is received
  109. };
  110.  
  111. /* global structure */
  112. struct S_ProcData
  113. {  
  114.    /* task data */
  115.    HTASK      hTask;              /* Task Id                              */
  116.    HWND       hFtpWnd;            /* Handle of the internal window        */
  117.    HWND       hParentWnd;         /* handle given to the FtpInit function */
  118.    HINSTANCE  hInstance;          /* Task Instance                        */
  119.  
  120.    /* Mesasge information */
  121.    struct S_Msg      Msg;      
  122.    struct S_Verbose  VMsg;      
  123.                                                                
  124.    /* File information */
  125.    struct S_FileTrf  File;  
  126.  
  127.    /* Ftp information */
  128.    struct S_FtpData   ftp;
  129.    
  130.    /* Linked list */
  131.    struct S_ProcData far *Next;
  132.    struct S_ProcData far *Prev;
  133. }; /* struct S_ProcData */
  134.  
  135. typedef struct S_ProcData far * LPProcData;
  136. typedef struct S_FtpData far *  LPFtpData;
  137.  
  138.  
  139.  
  140. /* **************************************************************** */
  141. /*                                                                  */
  142. /*                    P R O T O T Y P E S                           */
  143. /*                                                                  */
  144. /* **************************************************************** */
  145.  
  146. /* Utilities functions */
  147. LPProcData PASCAL FAR  FtpDataPtr (void);
  148. int PASCAL FAR WEP (int nType);
  149. int PASCAL FAR FtpSetVerboseMode (BOOL bVerboseMode, HWND hVerboseWnd, UINT wMsg);
  150.  
  151. /* Init functions */
  152. int PASCAL FAR FtpRelease (void);
  153. int PASCAL FAR FtpInit (HWND hParentWnd);
  154.  
  155. /* Connection */
  156. int PASCAL FAR FtpLogin (LPSTR szHost, LPSTR szUser, LPSTR szPasswd,
  157.                          HWND hParentWnd, UINT wMsg);
  158. int PASCAL FAR FtpOpenConnection (LPSTR szHost);
  159. int PASCAL FAR FtpCloseConnection (void);
  160. int PASCAL FAR FtpLocalClose (void);
  161.  
  162. /* authentification */
  163. int PASCAL FAR  FtpSendUserName (LPSTR szUserName);
  164. int PASCAL FAR  FtpSendPasswd (LPSTR szPasswd);
  165.  
  166. /* commands */
  167. int PASCAL FAR FtpHelp  (LPSTR szArg, LPSTR szBuf, UINT uBufSize);
  168. int PASCAL FAR FtpCWD   (LPSTR szPath);
  169. int PASCAL FAR FtpQuote (LPSTR szCmd, LPSTR szReplyBuf, UINT uBufSize);
  170.  
  171. /* file transfer */
  172. int PASCAL FAR FtpAbort (void);
  173. int PASCAL FAR FtpSendFile (LPSTR szLocal, LPSTR szRemote, char cType, 
  174.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  175. int PASCAL FAR FtpRecvFile (LPSTR szRemote, LPSTR szLocal, char cType, 
  176.                             BOOL bNotify, HWND hParentWnd, UINT wMsg);
  177. DWORD PASCAL FAR FtpGetFileSize (void);
  178.  
  179. /* Directory */
  180. int PASCAL FAR FtpDir (LPSTR szDef, LPSTR szLocalFile,
  181.                        BOOL  bLongDir, HWND  hParentWnd, UINT wMsg);
  182.  
  183. /* _______________________________________________________________ */
  184.  
  185. #define WFTP_API loaded
  186. #endif /* ifndef WFTP_API */
  187.  
  188.